<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>后台管理</title>
    <link rel="stylesheet" type="text/css" href="css/common.css"/>
    <link rel="stylesheet" type="text/css" href="css/main.css"/>
    <script type="text/javascript" src="js/libs/modernizr.min.js"></script>
	<script type="text/javascript" src="js/public.js"></script>
	<script> 
		window.onload = function (){
			var token = sessionStorage.getItem("token");
			if(token == null){
				window.location.href = "/shop/login.html";
			}
			var consumerName = sessionStorage.getItem("consumerName");
			var role = "店长";
			if(sessionStorage.getItem("role") != "1"){
							  role = "店员";
			}
			document.getElementById("manager_name").innerText = role+":"+consumerName;
			
		}
		function change_passwd(){
			var old = document.getElementById("password1").value;
			var new1 = document.getElementById("password2").value;
			var re = document.getElementById("password3").value;
			if(old==""||new1==""||re==""){
				alert("密码不能为空");
				return null;
			}else{
				if(new1!=re){
					alert("前后密码不一致");
					return null;
				}
				if(old==new1){
					alert("新旧密码不能一样");
					return null;
				}
			}
			var req = {
				oldPassword:old,
				newPassword:new1
			}
			
			fetch("http://localhost:8080/consumer/storePasswd",{method: 'POST',
				headers: {  
					'Content-Type': 'application/json',
					'token': sessionStorage.getItem("token"), 
					},  
				body:JSON.stringify(req),
				})
			
			    .then(response => {
			        // 确保服务器返回的是JSON数据
			        if (!response.ok) {
			            throw new Error('Failed to fetch data');
			        }
					return response.text();
					
			    })
				.then(data =>{
					let isSuccess = data.toLowerCase() === 'true';  
					        if (isSuccess) {  
					            alert("密码修改成功");  
					        } else {  
					            alert("密码修改失败");  
					        }  
				})
			    .catch(error => {
			        // 处理错误
			        console.error('Error:', error);
			    });
		}
	</script>
</head>
<body>
<div class="topbar-wrap white">
    <div class="topbar-inner clearfix">
        <div class="topbar-logo-wrap clearfix">
            <h1 class="topbar-logo none"><a href="admin.html" class="navbar-brand">后台管理</a></h1>
            <ul class="navbar-list clearfix">
                <li><a class="on" href="admin.html">后台管理首页</a></li>
            </ul>
        </div>
        <div class="top-info-wrap">
            <ul class="top-info-list clearfix">
                <li><a href="store.html" id= "manager_name">管理员</a></li>
                <li><a href="password.html">修改密码</a></li>
                <li><a href="#" onclick="logout()">退出</a></li>
            </ul>
        </div>
    </div>
</div>
<div class="container clearfix">
    <div class="sidebar-wrap">
        <div class="sidebar-title">
            <h1>菜单</h1>
        </div>
        <div class="sidebar-content">
            <ul class="sidebar-list">
                <li>
                    <a href="#"><i class="icon-font">&#xe003;</i>常用操作</a>
                    <ul class="sub-menu">
                        <li><a href="product.html"><i class="icon-font">&#xe008;</i>商品管理</a></li>
                        <li><a href="order.html"><i class="icon-font">&#xe005;</i>订单管理</a></li>
						<li><a href="insert.html"><i class="icon-font">&#xe005;</i>商品新增</a></li>
						<li><a href="category.html"><i class="icon-font">&#xe005;</i>类型管理</a></li>
                    </ul>
                </li>
                <li>
                    <a href="#"><i class="icon-font">&#xe018;</i>系统管理</a>
                    <ul class="sub-menu">
                        <li><a href="store.html"><i class="icon-font">&#xe017;</i>店铺信息设置</a></li>
						<li><a href="manager.html"><i class="icon-font">&#xe017;</i>个人信息设置</a></li>
						<li><a href="members.html"><i class="icon-font">&#xe017;</i>店铺成员信息</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
    <!--/sidebar-->
    <div class="main-wrap">
        <div class="result-wrap">
            <div class="result-title">
                <h1>修改密码</h1>
            </div>
            <div class="result-content">
                <ul class="sys-info-list">
                    <li>
                        <label class="res-lab">原始密码</label><input class="res-info" id="password1" type="password" value=""/><br />
						<label class="res-lab">新密码</label><input class="res-info" id="password2" type="password" value=""/><br />
						<label class="res-lab">确认密码</label><input class="res-info" id="password3" type="password" value=""/><br />
						<label class="res-lab"></label><input class="res-info"  type="button" value="修改" onclick="change_passwd()"/><br />
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <!--/main-->
</div>
<style>
.copyrights{text-indent:-9999px;height:0;line-height:0;font-size:0;overflow:hidden;}
</style>
<div class="copyrights">
  Collect from <a href="http://www.cssmoban.com/"  title="网站模板">模板之家</a>
  <a href="https://www.chazidian.com/"  title="查字典">查字典</a>
</div>
</body>
</html>